package com.moecollege.moecollegelib.ui;

import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.NavigationView;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.widget.RelativeLayout;

import com.moecollege.moecollegelib.R;
import com.moecollege.moecollegelib.adapter.FramePagerAdapter;
import com.moecollege.moecollegelib.base.BaseActivity;
import com.moecollege.moecollegelib.base.BaseFragment;
import com.moecollege.moecollegelib.log.MoeLog;
import com.moecollege.moecollegelib.utils.AndroidUtils;

import java.util.List;


/**
 * 主框架页面
 * Created by natsuki on 15/6/4.
 */
public abstract class MainFrameActivity extends BaseActivity {
    public Toolbar mToolBar;
    public AppBarLayout barLayout;
    public TabLayout tabLayout;
    public ViewPager tabViewPager;
    public List<String> mTitles;
    public List<BaseFragment> mPagers;
    public RelativeLayout headLayout;
    public NavigationView navigationView;
    public CollapsingToolbarLayout collapsingLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_frame);
        mToolBar = (Toolbar) findViewById(R.id.toolBar);
        barLayout = (AppBarLayout) findViewById(R.id.barlayout);
        headLayout = (RelativeLayout) findViewById(R.id.head_layout);
        navigationView = (NavigationView) findViewById(R.id.navigation);
        collapsingLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
        setSupportActionBar(mToolBar);
        tabLayout = (TabLayout) findViewById(R.id.tab_layout);
        tabViewPager = (ViewPager) findViewById(R.id.view_pager);
        mTitles = getTabTitles();
        mPagers = getPagers();
        int size = mPagers.size();
        for (int i = 0; i < size; i++) {
            tabLayout.addTab(tabLayout.newTab().setText(mTitles.get(i)));
        }
        FragmentPagerAdapter pagerAdapter = getPagerApdater();
        tabViewPager.setAdapter(pagerAdapter);
        tabLayout.setupWithViewPager(tabViewPager);
        tabLayout.setTabsFromPagerAdapter(pagerAdapter);
        collapsingLayout.setTitle("CollapsingToolbarLayout");
        //通过CollapsingToolbarLayout修改字体颜色
        collapsingLayout.setExpandedTitleColor(Color.WHITE);//设置还没收缩时状态下字体颜色
        collapsingLayout.setCollapsedTitleTextColor(Color.GREEN);//设置收缩后Toolbar上字体的颜色
    }

    protected abstract List<String> getTabTitles();

    protected abstract List<BaseFragment> getPagers();

    public FragmentPagerAdapter getPagerApdater() {
        return new FramePagerAdapter(getSupportFragmentManager(), mTitles, mPagers);
    }

}
